

#pragma once

#include "config/parameter_group.h"
#include "common/time.h"
#include "drivers/sonar_hcsr04.h"

#define SONAR_OUT_OF_RANGE (-1)

extern int16_t sonarMaxRangeCm;
extern int16_t sonarCfAltCm;
extern int16_t sonarMaxAltWithTiltCm;

PG_DECLARE(sonarConfig_t, sonarConfig);

void sonarInit(const sonarConfig_t *sonarConfig);
void sonarUpdate(timeUs_t currentTimeUs);
int32_t sonarRead(void);
int32_t sonarCalculateAltitude(int32_t sonarDistance, float cosTiltAngle);
int32_t sonarGetLatestAltitude(void);
